SK
sistema

Pvp System Control

Por SkyDangerous, 19 de jun. de 2012 em Mods, funções e outros

skydangerous
script
23
6.9k
SkyDangerousS
19 de junho de 2012 às 23:57

Função:

Você pode alterar o seu tipo de pvp, utilizando o comando !pvp on, para conseguirem te atacar e !pvp off para não te atacarem

 

SQL QUERY

ALTER TABLE `players` ADD `pvpmode` BOOL NOT NULL ;

 

 

em data/lib/function.lua

function getPlayerPVPMode(uid)
 local result = db.getResult("SELECT `pvpmode` FROM `players` WHERE `name` = '" .. getPlayerName(uid) .. "' LIMIT 1;")
  if(result:getID() ~= -1) then
local mode = result:getDataInt("pvpmode")
return mode
  else
return FALSE
  end
  result:free()
end

function setPlayerPVPMode(uid, value)
 if (value >= 0 and value <= 1) then
  if isPlayer(uid) == TRUE then
db.executeQuery("UPDATE `players` SET `pvpmode` = " .. value .. " WHERE `name`='" .. getPlayerName(uid) .. "' LIMIT 1;")
return TRUE
  else
return FALSE
  end
 else
  return FALSE
 end
end

 

 

data/talkactions/scripts/pvpmode.lua

function onSay(cid, words, param)
   local mode = getPlayerPVPMode(cid)
   if mode == 1 then
       setMode = 0
   else
       setMode = 1
   end
   if isPlayerPzLocked(cid) == FALSE and getCreatureSkullType(cid) == SKULL_NONE then
       setPlayerPVPMode(cid, setMode)
       if setMode == 1 then
           doPlayerSendTextMessage(cid, 19, "Now you set pvp mode to on!")
       else
           doPlayerSendTextMessage(cid, 19, "Now you set pvp mode to off!")
       end
   else
       doPlayerSendCancel(cid, "You cannot set pvp mode when you are agressive.")
   end
   return TRUE
end

 

talkactions.xml

<talkaction log="no" words="!pvp" access="0" event="script" value="pvpmode.lua">

 

login.lua

registerCreatureEvent(cid, "PVPMode")

 

data/creaturescripts/scripts/pvpProtection.lua

function onCombat(cid, target)
   if (getPlayerPVPMode(cid) == 1 and getPlayerPVPMode(target) == 1) or isPlayer(target) == FALSE then
       return TRUE
   else
       doPlayerSendCancel(cid, "You cannot attack players which pvp mode is off.")
       return FALSE
   end
end

 

creaturescripts.xml

<event type="combat" name="PVPMode" event="script" value="pvpProtection.lua">

</event></talkaction>

 

Credits

Gevox

Editado Junho 19 por SkyDangerous

fredpaduaF
20 de junho de 2012 às 00:27

Sky, esse comando pode ser usado toda hora ?

Tem como por um delay , e tambem só poderia ativar sem battle?

SkyDangerousS
20 de junho de 2012 às 00:38

Sky, esse comando pode ser usado toda hora ?

Tem como por um delay , e tambem só poderia ativar sem battle?

 

é isso que eu vou por depois.

 

kk', pra nao ficar toda hora trocando.

DeadpoolD
20 de junho de 2012 às 11:30

e.e Muito Bom #@SkyDangerous :D

MaXwEllDeNM
20 de junho de 2012 às 11:45

Fico bacana Sky, Parabéns REP +;

 

 

Tipo, não usa FALSE nem TRUE cara, usa false e true, FALSE e TRUE são macros, não booleanos;

 

 

Poe ae um event onAttack também pra não poder atacar o cara, ai só vai previnir que o cara não tome o dano, e tipo a msg você poe só no onAttack, no onCombat não precisa porque se não vai ficar tipo, toda hora que o cara tentar hitar mandando a mensagem, mesmo se tiver sido um ataque em área!

VodkartV
20 de junho de 2012 às 12:21

fico bom, mas de vez de fazer por db, daria pra fazer por storage...

SkyDangerousS
20 de junho de 2012 às 12:40

e.e Muito Bom #@SkyDangerous :D

 

Vlw :p

 

 

Fico bacana Sky, Parabéns REP +;

 

 

Tipo, não usa FALSE nem TRUE cara, usa false e true, FALSE e TRUE são macros, não booleanos;

 

 

Poe ae um event onAttack também pra não poder atacar o cara, ai só vai previnir que o cara não tome o dano, e tipo a msg você poe só no onAttack, no onCombat não precisa porque se não vai ficar tipo, toda hora que o cara tentar hitar mandando a mensagem, mesmo se tiver sido um ataque em área!

 

Ok, irei modificar.

Vlw

 

fico bom, mas de vez de fazer por db, daria pra fazer por storage...

 

Sim, eu já fiz por storage.. é bem parecido ;D

KUNGLOWK
20 de junho de 2012 às 16:38

Teria como fazer pra um npc ativar e desativar o PVP? e assim que o player ativasse o PVP ele ganha uma skull amarela?

 

To com um erro aqui ao adicionar o código no SQL

 

Error while executing query: Cannot add a NOT NULL column with default value NULL

VodkartV
20 de junho de 2012 às 17:08

Se eu não me engano tem um bug, porque os dois jogadores tem que ta usando pra não poderem se atacar, ou seja se JOÃO tiver no modo seguro e MARIA não, MARIA ainda vai poder atacar o JOÃO... usa assim:

 

query:

 

ALTER TABLE `players` ADD `pvpmode` INT NOT NULL DEFAULT '0'

 

e script fiz em MODS

 

PvpMode.xml

<?xml version="1.0" encoding="UTF-8"?>  
<mod name="Pvp Mode" version="1.0" author="Gevox" contact="xtibia.com" enabled="yes">  
<config name="pvpmode_func"><![CDATA[
function getPlayerPVPMode(cid)
local check = db.getResult("SELECT `pvpmode` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
return check:getDataInt("pvpmode") <= 0 and 0 or check:getDataInt("pvpmode")
end
function setPlayerPVPMode(cid, value)
db.executeQuery("UPDATE `players` SET `pvpmode` = "..value.." WHERE `id` = "..getPlayerGUID(cid))
end
]]></config>
<talkaction words="/pvp;!pvp" event="buffer"><![CDATA[
domodlib('pvpmode_func')
if isPlayerPzLocked(cid) == FALSE and getCreatureSkullType(cid) == SKULL_NONE then
	setPlayerPVPMode(cid, getPlayerPVPMode(cid) == 0 and 1 or 0)
		doPlayerSendTextMessage(cid, 19, "Now you set pvp mode to "..(getPlayerPVPMode(cid) == 0 and "off" or "on").."!")
else
	doPlayerSendCancel(cid, "You cannot set pvp mode when you are agressive.")
end
return true
]]></talkaction>
<event type="login" name="PvpModeRegister" event="script"><![CDATA[
function onLogin(cid)
registerCreatureEvent(cid, "pvpProtection")
return true
end]]></event>	  
<event type="combat" name="pvpProtection" event="script"><![CDATA[
domodlib('pvpmode_func')
if isPlayer(cid) and isPlayer(target) then
if getPlayerPVPMode(cid) == 1 or getPlayerPVPMode(target) == 1 then
doPlayerSendCancel(cid, "You may not attack this player.")
return false
end
end
return true
]]></event>
</mod>

 

 

 

obs: ainda prefiro fazer por storage

Editado Junho 20 por Vodkart

Nathan96N
20 de junho de 2012 às 17:22

O nosso querido jhon992 fez um pra min com stogare como disse o Vodkart eu achei mais pratico.

KUNGLOWK
20 de junho de 2012 às 17:38

Funcinou tem como assim que o player ativar o PVP ele ganhar uma Yellow Skull?

VodkartV
20 de junho de 2012 às 17:49

Funcinou tem como assim que o player ativar o PVP ele ganhar uma Yellow Skull?

 

<?xml version="1.0" encoding="UTF-8"?>  
<mod name="Pvp Mode" version="1.0" author="Gevox" contact="xtibia.com" enabled="yes">  
<config name="pvpmode_func"><![CDATA[
function getPlayerPVPMode(cid)
local check = db.getResult("SELECT `pvpmode` FROM `players` WHERE `id` = " .. getPlayerGUID(cid) .. " LIMIT 1")
return check:getDataInt("pvpmode") <= 0 and 0 or check:getDataInt("pvpmode")
end
function setPlayerPVPMode(cid, value)
db.executeQuery("UPDATE `players` SET `pvpmode` = "..value.." WHERE `id` = "..getPlayerGUID(cid))
end
]]></config>
<talkaction words="/pvp;!pvp" event="buffer"><![CDATA[
domodlib('pvpmode_func')
if isPlayerPzLocked(cid) == FALSE and isInArray({SKULL_NONE,SKULL_YELLOW}, getCreatureSkullType(cid)) then
	setPlayerPVPMode(cid, getPlayerPVPMode(cid) == 0 and 1 or 0)
doCreatureSetSkullType(cid, getPlayerPVPMode(cid) == 1 and 1 or 0)
		doPlayerSendTextMessage(cid, 19, "Now you set pvp mode to "..(getPlayerPVPMode(cid) == 0 and "off" or "on").."!")
else
	doPlayerSendCancel(cid, "You cannot set pvp mode when you are agressive.")
end
return true
]]></talkaction>
<event type="login" name="PvpModeRegister" event="script"><![CDATA[
domodlib('pvpmode_func')
function onLogin(cid)
registerCreatureEvent(cid, "pvpProtection")
if getPlayerPVPMode(cid) == 1 then doCreatureSetSkullType(cid, 1) end
return true
end]]></event>	  
<event type="combat" name="pvpProtection" event="script"><![CDATA[
domodlib('pvpmode_func')
if isPlayer(cid) and isPlayer(target) then
if getPlayerPVPMode(cid) == 1 or getPlayerPVPMode(target) == 1 then
doPlayerSendCancel(cid, "You may not attack this player.")
return false
end
end
return true
]]></event>
</mod>

Editado Junho 20 por Vodkart

KUNGLOWK
20 de junho de 2012 às 18:27

Outra pergunta tem como fazer isso so que por NPC?

VodkartV
20 de junho de 2012 às 18:47

óbvio que tem, você diz trocar a talk por npc né.

SweetEvulS
20 de junho de 2012 às 19:13

Muito interessante , mas se o player pode utilizar o comando com battle ficaria bem feio . rs